﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Mystery.SharePoint
{
    /// <summary>
    /// Extensions for strings
    /// </summary>
    public static class StringExtensions
    {
        /// <summary>
        /// Creates a list of strings using a provided seperator
        /// </summary>
        /// <param name="text"></param>
        /// <param name="seperator">The seperation string</param>
        /// <returns></returns>
        public static List<string> CreateList(this string text, string seperator)
        {
            if (string.IsNullOrEmpty(seperator) == true) throw new ArgumentNullException("seperator");
            if (string.IsNullOrEmpty(text) == true) return new List<string>();

            return new List<string>(text.Split(seperator.ToCharArray(), StringSplitOptions.RemoveEmptyEntries));
        }
        /// <summary>
        /// Ensures that a string ends with something
        /// </summary>
        /// <param name="text"></param>
        /// <param name="trail">The string it should end with</param>
        /// <returns>A string with the specified trail</returns>
        public static string EnsureTrail(this string text, string trail)
        {
            if (string.IsNullOrEmpty(text) == true) throw new ArgumentNullException("text");
            if (string.IsNullOrEmpty(trail) == true) throw new ArgumentNullException("trail");

            if (text.EndsWith(trail) == false)
            {
                return text + trail;
            }
            return text;
        }
    }
}
